package cn.edu.ujn.project.supermarket.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.ujn.project.common.core.text.Convert;
import cn.edu.ujn.project.supermarket.domain.ChargeReport;
import cn.edu.ujn.project.supermarket.domain.VipUser;
import cn.edu.ujn.project.supermarket.extendbean.ChargeReportChild;
import cn.edu.ujn.project.supermarket.mapper.ChargeReportMapper;
import cn.edu.ujn.project.supermarket.mapper.VipUserMapper;
import cn.edu.ujn.project.supermarket.service.IChargeReportService;
import cn.edu.ujn.project.system.mapper.SysUserMapper;


/**
 * 充值记录表Service业务层处理
 * 
 * @author zhaomh
 * @date 2023-11-13
 */
@Service
public class ChargeReportServiceImpl implements IChargeReportService 
{
    @Autowired
    private ChargeReportMapper chargeReportMapper;
    @Autowired
    private SysUserMapper userMapper;
    @Autowired
    private VipUserMapper vipUserMapper;
    /**
     * 查询充值记录表
     * 
     * @param chargeId 充值记录表主键
     * @return 充值记录表
     */
    @Override
    public ChargeReport selectChargeReportByChargeId(String chargeId)
    {
        return chargeReportMapper.selectChargeReportByChargeId(chargeId);
    }

    /**
     * 查询充值记录表列表
     * 
     * @param chargeReport 充值记录表
     * @return 充值记录表
     */
    @Override
    public List<ChargeReport> selectChargeReportList(ChargeReport chargeReport)
    {
        return chargeReportMapper.selectChargeReportList(chargeReport);
    }

    /**
     * 新增充值记录表
     * 
     * @param chargeReport 充值记录表
     * @return 结果
     */
    @Override
    public int insertChargeReport(ChargeReport chargeReport)
    {
        return chargeReportMapper.insertChargeReport(chargeReport);
    }

    /**
     * 修改充值记录表
     * 
     * @param chargeReport 充值记录表
     * @return 结果
     */
    @Override
    public int updateChargeReport(ChargeReport chargeReport)
    {
        return chargeReportMapper.updateChargeReport(chargeReport);
    }

    /**
     * 批量删除充值记录表
     * 
     * @param chargeIds 需要删除的充值记录表主键
     * @return 结果
     */
    @Override
    public int deleteChargeReportByChargeIds(String chargeIds)
    {
        return chargeReportMapper.deleteChargeReportByChargeIds(Convert.toStrArray(chargeIds));
    }

    /**
     * 删除充值记录表信息
     * 
     * @param chargeId 充值记录表主键
     * @return 结果
     */
    @Override
    public int deleteChargeReportByChargeId(String chargeId)
    {
        return chargeReportMapper.deleteChargeReportByChargeId(chargeId);
    }
    //================================================================
    /**
     * 查询充值记录表
     * 
     * @param chargeId 充值记录表主键
     * @return 充值记录表
     */
    public String getUserName(String vipId)
    {
    	VipUser userByVipId = vipUserMapper.selectVipUserByVipId(vipId);
        return userMapper.selectUserById(Long.valueOf(userByVipId.getUserId())).getUserName();
    }
    @Override
    public ChargeReportChild selectChargeReportChildByChargeId(String chargeId)
    {
    	ChargeReport chargeReport = chargeReportMapper.selectChargeReportByChargeId(chargeId);
        return new ChargeReportChild(getUserName(chargeReport.getVipId()), chargeReport);
    }

    /**
     * 查询充值记录表列表
     * 
     * @param chargeReport 充值记录表
     * @return 充值记录表
     */
    @Override
    public List<ChargeReportChild> selectChargeReportChildList(ChargeReportChild chargeReport)
    {
//    	ArrayList<ChargeReportChild> list = new ArrayList<ChargeReportChild>();
//        List<ChargeReport> selectChargeReportList = chargeReportMapper.selectChargeReportList(chargeReport);
//        for (ChargeReport chargeReport2 : selectChargeReportList) {
//			list.add(new ChargeReportChild(getUserName(chargeReport2.getVipId()),
//					chargeReport2));
//		}
//        return list;
        return this.chargeReportMapper.selectChargeReportChildList(chargeReport);
    }

    /**
     * 新增充值记录表
     * 
     * @param chargeReport 充值记录表
     * @return 结果
     */
    @Override
    public int insertChargeReportChild(ChargeReportChild chargeReport)
    {
        return chargeReportMapper.insertChargeReport(chargeReport);
    }

    /**
     * 修改充值记录表
     * 
     * @param chargeReport 充值记录表
     * @return 结果
     */
    @Override
    public int updateChargeReportChild(ChargeReportChild chargeReport)
    {
        return chargeReportMapper.updateChargeReport(chargeReport);
    }

    /**
     * 批量删除充值记录表
     * 
     * @param chargeIds 需要删除的充值记录表主键
     * @return 结果
     */
    @Override
    public int deleteChargeReportChildByChargeIds(String chargeIds)
    {
        return chargeReportMapper.deleteChargeReportByChargeIds(Convert.toStrArray(chargeIds));
    }

    /**
     * 删除充值记录表信息
     * 
     * @param chargeId 充值记录表主键
     * @return 结果
     */
    @Override
    public int deleteChargeReportChildByChargeId(String chargeId)
    {
        return chargeReportMapper.deleteChargeReportByChargeId(chargeId);
    }
}
